/******************************************************************************
 * (C) Copyright 2013 Atech-Automotive
 * FILE NAME:    hwa_e2.h
 * DESCRIPTION:
 * 
 * DATE BEGUN:   
 * BY:                         
 * PRODUCT NAME:
 * APPLICATION:
 * TARGET H/W:
 * DOC REF:
 *****************************************************************************
 */

#ifndef _HWA_E2_H_
#define _HWA_E2_H_


/*****************************************************************************
**#include 
*****************************************************************************/

#include "hwa_e2_callback.h"

/*****************************************************************************
**  typedef
*****************************************************************************/

typedef enum
{
    E2_STATUS_IDLE      = 0U,
    E2_STATUS_PENDING   = 1U,
    E2_STATUS_ERROR     = 2U,
    E2_STATUS_RD_DONE   = 3U,
    E2_STATUS_WR_DONE   = 4U,
    E2_STATUS_DEL_DONE  = 5U,
    E2_STATUS_INIT_DONE = 6U

} E2_STATUS_E;

typedef enum
{
    E2_REQUEST_IDLE           = 0U,  
    E2_REQUEST_WR             = 1U,
    E2_REQUEST_RD             = 2U,
    E2_REQUEST_RECOVER_NORMAL = 3U,
    E2_REQUEST_RECOVER_BACKUP = 4U,
    E2_REQUEST_INIT           = 5U
    
} E2_Request_E;


/*****************************************************************************
** Constant Macro Definition
*****************************************************************************/

/*****************************************************************************
** System Macro Definition
*****************************************************************************/


/*****************************************************************************
** Action Macro Definition
*****************************************************************************/


/*****************************************************************************
** Config Macro Definition
*****************************************************************************/


/*****************************************************************************
** Task Macro Definition
*****************************************************************************/


/*****************************************************************************
** Variables
*****************************************************************************/


/*****************************************************************************
** Constants
*****************************************************************************/


/*****************************************************************************
** Function prototypeseb
*****************************************************************************/
/****************************************************************************/
/**
 * Function Name: hwa_e2GetVersion
 * Description: Get Software Version
 *
 * Param:   none
 * Return:  Pointer of the version Variable about software version information.
 * Author:                  
 ****************************************************************************/
//EE_VersionType_S const * hwa_e2GetVersion( void );

/****************************************************************************/
/**
 * Function Name: hwa_e2Init
 * Description: Initialize EEPROM module
 *
 * Param:   none
 * Return:  none
 * Author:  2014/02/24,                 
 ****************************************************************************/
void hwa_e2Init( void );

/****************************************************************************/
/**
 * Function Name: hwa_e2ReadDataById
 * Description: Sending request to E2 scheduler for read.
 *              Don't invoked this function in interrupt.
 *
 * Param arg1 data_id_U8: Request data id
 *
 * Return:  TRUE  - ID is idle, set read request.
 *          FALSE - ID is busy, don't set the read request. 
 * Author:                   
 ****************************************************************************/
BOOL hwa_e2ReadDataById( UINT8 idx, UINT32 * p_u32_read );

/****************************************************************************/
/**
 * Function Name: hwa_e2WriteDataById
 * Description: Sending request to E2 scheduler for write or write and read
 *
 * Param arg1 data_id_U8: Request data id
 *       arg2 data_ptr: Pointer of write data
 *
 * Return:  TRUE:  ID is idle, set write request.
 *          FALSE: ID is busy, don't set the write request. 
 * Author:  2014/02/24,                 
 ****************************************************************************/
BOOL hwa_e2WriteDataById( UINT8 idx, UINT32 u32_wr_data ); 

/****************************************************************************/
/**
 * Function Name: hwa_e2GetRequest
 * Description: Return the request of E2
 *
 * Param arg1 idx: Request data id
 *
 * Return:  E2_REQUEST_IDLE		         ((UINT8)0)
 *          E2_REQUEST_WR  	             ((UINT8)1)
 *          E2_REQUEST_RD	  	         ((UINT8)2)
 *          E2_REQUEST_RECOVER_NORMAL  	 ((UINT8)3)
 *          E2_REQUEST_RECOVER_BACKUP	 ((UINT8)4)  
 * Author:                  
 ****************************************************************************/
E2_Request_E hwa_e2GetRequest( UINT8 idx );

/****************************************************************************/
/**
 * Function Name: hwa_e2Handler1ms
 * Description: Runs unified state machine for e2 read and write	
 *
 * Param:   none
 * Return:  none
 * Author:                  
 ****************************************************************************/
void hwa_e2Handler1ms( void );

#if 0
/****************************************************************************/
/**
 * Function Name: Driver_E2WriteDirect
 * Description: Write 4 byte into the address in eeprom.
 *              1. Please the addr must be (addr % 4 == 0).
 *              2. Return False if want to WR user space.
 *              3. G128 that allowed be used: 0x400 - 0x11FF
 *              4. G48 that allowed be used: 0x400 - 0x7FF
 *
 * Param:   none
 * Return:  TRUE  - operation success
 *          FALSE - operation failure
 * Author:                  
 ****************************************************************************/
void hwa_e2WriteAddrDirect( UINT8 *pBuf, UINT16 addr );

/****************************************************************************/
/**
 * Function Name: Driver_E2EraseSectorDirect
 * Description: Erase 4 byte into the address in eeprom.
 *              1. Please the addr must be (addr % 4 == 0).
 *              2. Return False if want to WR user space.
 *              3. G128 that allowed be used: 0x400 - 0x11FF
 *              4. G48 that allowed be used: 0x400 - 0x7FF
 *
 * Param:   none
 * Return:  none
 * Author:                  
 ****************************************************************************/
BOOL Driver_E2EraseSectorDirect( UINT16 addr );

#endif

/*****************************************************************************
** other
*****************************************************************************/


/****************************************************************************/

#endif	//_HWA_E2_H_

/*****************************************************************************
** End File
*****************************************************************************/

